package com.util;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;


public class Constants {
	public static final int OK = 1;
	public static final int ERROR = -1;	

	static {
		install();
	}
	//action 返回
	static String LOGIN="login";
	static String SUCCESS="success";
	static String ERRORS="errors";
	static String INPUT="input";	
	
	//Memcached keyset

	//路路通用户版本号
	public static String LULUTONG_CACHE_VERSION = "LULUTONG_CACHE_VERSION";
	//路路通用户缓存(USER_用户ID_版本号)
	public static final String LULUTONG_USER_PREFIX = "LULUTONG_USER_";
	//路路通活动缓存(HUODONG_活动编号_版本号)
	public static final String LULUTONG_HUODONG_PREFIX = "HUODONG_";
	//路路通活动缓存(CUXIAO_促销编号_版本号) 促销包括---返券，赠送，品尝
	public static final String LULUTONG_CUXIAO_PREFIX = "CUXIAO_";
	//路路通返券缓存(FANQUAN_活动编号_版本号)
	public static final String LULUTONG_FANQUAN_PREFIX = "FANQUAN_";
	//路路通赠送缓存(ZENSONG_活动编号_版本号)
	public static final String LULUTONG_ZENSONG_PREFIX = "ZENSONG_";
	//路路通品尝缓存(PINCHANG_活动编号_版本号)
	public static final String LULUTONG_PINCHANG_PREFIX = "PINCHANG_";
	//路路通特价菜缓存(TEJIACAI_特价菜编号_版本号)
	public static final String LULUTONG_TEJIACAI_PREFIX = "TEJIACAI_";
	//路路通经理人缓存(JINLIREN_经理人编号_版本号)
	public static final String LULUTONG_JINLIREN_PREFIX = "JINLIREN_";
	//餐厅信息缓存
	public static final String CLIENTINFO_PREFIX = "CLIENTINFO_";
	
	
	//路路通菜谱图片缓存(CLIENT_MENU_菜谱编号_YYYYMMDD_版本号)
	public static final String CLIENT_MENU_PREFIX = "CLIENT_MENU_";	
	// 路路通餐厅图片(CLIENT_IMAGES_餐厅编号_版本号)
	public static final String CLIENT_IMAGES_PREFIX = "CLIENT_IMAGES_";
	
	//路路通饭统会员缓存(CLIENT_FANTONGMEMBERS_CITYID_版本号)
	public static final String CLIENT_FANTONGMEMBERS_PREFIX = "CLIENT_FANTONGMEMBERS_";
	//路路通饭统会员取会员总行数
	public static final int rowmaxnum = 2000;
	
	//路路通本餐厅会员数量(LULUTONG_CLIENTMEMBER_CLIENTID_NUM_版本号)
	public static final String LULUTONG_CLIENTMEMBER_NUM_PREFIX = "LULUTONG_CLIENTMEMBER_NUM_";
	//路路通饭统会员总行数
	public static final String LULUTONG_FANTONGMEMBER_NUM_PREFIX = "LULUTONG_FANTONGMEMBER_NUM_";
	
	//路路通周围餐厅促销情况
	public static final String LULUTONG_TASKAROUND_PREFIX = "LULUTONG_AROUND_CATE_";
	
	/********************************************************************
	 * 
	 * 定义路路通登录相关常量
	 * 
	 ********************************************************************/
	
	//登录后session中保存的用户信息
	public static final String LLT_LOGIN_USERSESSION = "UserInfo";
	/**
	 * 餐厅信息 ClientInfo
	 */
	public static final String LLT_CLIENTINFO = "ClientInfo";
	
	//路路通用户注册信息不完全
	public static final String LLT_REG_INFOEMPTY = "请完整填写注册表单！";
	//路路通注册用户名邮箱已经存在
	public static final String LLT_REG_EXISTUSERORMAIL = "用户名已经存在 ，请返回重新注册";
	//路路通用户Cookie的key
	public static final String LLT_COOKIE_KEY = "llt_userinfo_cookie";	
	//初始化缓存版本
	public static void install()  {
		if (CacheTool.get("LULUTONG_CACHE_VERSION") == null) {
			HashMap<String, String> hm = new HashMap<String, String>();
			hm.put("LULUTONG_USER_VERSION", "1");
			hm.put("LULUTONG_CUXIAO_VERSION", "1");
			hm.put("LULUTONG_HUODONG_VERSION", "1");
			hm.put("LULUTONG_FANQUAN_VERSION", "1");
			hm.put("LULUTONG_ZENSONG_VERSION", "1");
			hm.put("LULUTONG_PINCHANG_VERSION", "1");
			hm.put("LULUTONG_TEJIACAI_VERSION", "1");
			hm.put("LULUTONG_JINLIREN_VERSION", "1");
			hm.put("LULUTONG_CLIENTINFO_VERSION", "1");
			hm.put("CLIENT_MENU_VERSION", "1");
			hm.put("CLIENT_FANTONGMEMBERS_VERSION", "1");
			hm.put("LULUTONG_FANTONGMEMBER_NUM_VERSION", "1");
			hm.put("LULUTONG_CLIENTMEMBER_NUM_VERSION", "1");
			hm.put("LULUTONG_AROUND_CATE_VERSION", "1");
			CacheTool.set("LULUTONG_CACHE_VERSION", hm);
		}
	}
	
	//生成缓存key
	public static String strCreatCacheKey(String perfix,String strNo ,String strVersion){
		StringBuilder key = new StringBuilder();
		key.append(perfix);
		key.append(strNo);
		key.append("_");
		key.append(strVersion);
		return key.toString();
	}
	/**
	 * 餐厅上传图片
	 * @param perfix
	 * @param strClientId
	 * @param strVersion
	 * @return
	 */
	public static String creatClientImagesCacheKey(String perfix,String strClientId,String strVersion){
		StringBuilder key = new StringBuilder();
		key.append(perfix);
		key.append(strClientId);
		key.append("_");
		key.append(strVersion);
		return key.toString();
	}	
	
	
	/**
	 * 菜谱图片缓存键生成策略
	 * @param perfix 前缀
	 * @param strMenuId 菜谱编号
	 * @param strVersion 版本
	 * @return key 菜谱图片缓存键生成策略
	 */
	public static String creatClientMenuCacheKey(String perfix,String strMenuId,String strVersion){
		StringBuilder key = new StringBuilder();
		key.append(perfix);
		key.append(strMenuId);
		key.append("_");
		key.append(""+DateUtil.DATE_FORMAT_NUM.format(new Date()));
		key.append("_");
		key.append(strVersion);
		return key.toString();
	}
	
	/**
	 * 取Cache的Key
	 * @param versionType
	 * @param prefix
	 * @param clientid
	 * @return
	 */
	public static String getCacheKey(String versionType,String prefix, String clientid){
		Object obj = CacheTool.get("LULUTONG_CACHE_VERSION");//获取版本号
		String vs = null, key = null;
		if(obj != null){
			Map<String, String> vMap = (HashMap<String, String>)obj;
			vs = vMap.get(versionType);
			key = Constants.strCreatCacheKey(prefix, clientid, vs);
		}
		return key;
	}
}
